<template>
	<view>
		<uni-nav-bar dark title="全部事件" fixed :statusBar="true" left-icon="left" @clickLeft="onLeft">

		</uni-nav-bar>
		<view class="list" v-for="(item,index) in list" :key="index">
			<view class="left">
				<view class="info">
					<view >第{{item.subsection}}节 {{item.teamName}}</view>
					<view>{{item.time}}</view>
				</view>
				<view class="data">
					<view  @click="onSelctTeamName(item.id,item.basketballPlayerId)">{{item.playerNumber}}号 {{item.name}}</view>
					<view class="flex align-center">
						<view  class="margin-lr-xs" @click="onSelctType(item.id)">{{item.typeStr}}</view>
						
						<uni-icons type="trash" @click="onDel(item.id)" size="30" color="red"></uni-icons>

					</view>
					
				</view>
			</view>

		</view>
		<uni-load-more :status="loadingType"></uni-load-more>

		<!--  -->
		<uni-popup ref="popup" type="cetner" border-radius="10px 10px 0 0">
			<view class="selectTeam">
				<uni-data-select style="width: 280rpx;"  :localdata="teamList" @change="change"></uni-data-select>
				<button @click="onClost('popup')" style="margin-top: 20rpx;">关闭</button>
			</view>
		</uni-popup>
		
		<!--  -->
		<uni-popup ref="popup1" type="cetner" border-radius="10px 10px 0 0">
			<view class="selectTeam">
				<uni-data-select style="width: 280rpx;"  :localdata="downbox" @change="change1"></uni-data-select>
				<button @click="onClost('popup1')" style="margin-top: 20rpx;">关闭</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getplayerLogList,
		putplayerLog,
		getdownBox,
		delplayerLog
	} from '@/api/record/index.js'
	export default {
		data() {
			return {
				list: [],
				page: {
					pageNum: 1,
					pageSize: 12
				},
				basketballPlayerId: '',
				tournamentId: '',
				total: 0,
				loadingType: 'more',
				teamList: [],
				id:'',
				downbox: [],
				// teamList1:[],
				// teamList2:[]
			}
		},
		methods: {
			onDel(id) {
				uni.showModal({
					content: '确定删除吗？',
					success: (res) => {
						if (res.confirm) {
							delplayerLog(id).then(res => {
								this.list = []
								this.page =  {
									pageNum: 1,
									pageSize: 12
								},
								this.getList();
								uni.setStorageSync('isRefresh', true);
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			change1(val) {
				putplayerLog({id: this.id, type: val}).then(res =>{
					this.page = {
						pageNum: 1,
						pageSize: 10
					}
					this.list = []
					this.getList()
					this.$refs['popup1'].close();
					uni.setStorageSync('isRefresh', true);
				})
			},
			change(val) {
				console.log(val)
				putplayerLog({id: this.id, basketballPlayerId: val}).then(res =>{
					this.page = {
						pageNum: 1,
						pageSize: 10
					}
					this.list = []
					this.getList()
					this.$refs['popup'].close();
					uni.setStorageSync('isRefresh', true);
				})
			},
			onClost(text) {
				this.$refs[text].close();
			},
			onSelctType(id) {
				this.id = id
				this.$refs.popup1.open('center')
			},
			onSelctTeamName(id,basketballPlayerId) {
				let players = uni.getStorageSync('two').filter(item => item.id == basketballPlayerId)
				console.log(this.teamList,"----basketballPlayerId")
				if (players.length) {
					this.teamList = uni.getStorageSync('two').map(item => {
						return{...item, text:item.name +` (${item.playerNumber})`, value: item.id}
					})
				} else {
					this.teamList = uni.getStorageSync('one').map(item => {
						return{...item, text:item.name +` (${item.playerNumber})`, value: item.id}
					})
				}
				this.id = id
				this.$refs.popup.open('center')
			},
			onLeft() {
				uni.navigateBack()
			},
			getList() {
				getplayerLogList({
					// basketballPlayerId: this.basketballPlayerId,
					tournamentId: this.tournamentId,
					...this.page
				}).then(res => {
					this.total = res.total
					this.list.push(...res.rows)
					if (this.list.length == this.total) {
						this.loadingType = 'no-more'
						return;
					}
				})
			}
		},
		async onReachBottom() {
			if (this.list.length == this.total) {
				this.loadingType = 'no-more'
				return;
			}
			this.loadingType = 'loading'
			this.page.pageNum += 1
			this.getList()
		},
		onLoad({
			basketballPlayerId,
			tournamentId,
			typeList
		}) {
			this.tournamentId = tournamentId;
			this.basketballPlayerId = basketballPlayerId;
			this.getList()
			getdownBox().then(res => {
				this.downbox = res.data.map(item => {
					return {...item, value: item.code,text: item.info}
				})
			});
			// if (typeList == 0) {
			// 	this.teamList = uni.getStorageSync('one').map(item => {
			// 		return{...item, text:item.name +` (${item.playerNumber})`, value: item.id}
			// 	})
			// } else {
			// 	this.teamList = uni.getStorageSync('two').map(item => {
			// 		return{...item, text:item.name +` (${item.playerNumber})`, value: item.id}
			// 	})
			// }
		}
	}
</script>

<style scoped lang="scss">
	.selectTeam {
		padding: 30rpx;
		background-color: #fff;;
	}
	.list {
		display: flex;
		width: 100%;
		padding: 30rpx 20rpx 0 20rpx;

		.left {
			display: flex;
			flex-direction: column;
			width: 100%;

			.info {
				width: 100%;
				display: flex;
				justify-content: space-between;
				font-size: 26rpx;
				margin-bottom: 10rpx;

				view {
					&:nth-child(1) {
						display: flex;

						&:before {
							display: flex;
							content: ' ';
							width: 8rpx;
							height: 100%;
							background-color: red;
							margin-right: 16rpx;
						}
					}
				}
			}

			.data {
				display: flex;
				width: 100%;
				padding: 20rpx;
				justify-content: space-between;
				background-color: #eee;
			}
		}
	}
</style>